package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.ApplyToProgEmployAddDTO;
import org.jsola.hr.dto.ApplyToProgEmployUpdateDTO;
import org.jsola.hr.entity.ApplyToProgEmployDO;
import org.jsola.hr.query.ApplyToProgEmployQuery;
import org.jsola.hr.service.IApplyToProgEmployService;
import org.jsola.hr.vo.ApplyToProgEmployVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class ApplyToProgEmployTestHelper extends BaseTestHelper {
    
    @Autowired
    private IApplyToProgEmployService applyToProgEmployService;

    /**
     * 生成add测试数据
     * @return ApplyToProgEmployAddDTO
     */
    public ApplyToProgEmployAddDTO getApplyToProgEmployAddDTO(){
        ApplyToProgEmployAddDTO applyToProgEmployAddDTO = new ApplyToProgEmployAddDTO();
        applyToProgEmployAddDTO.setProgId(getRandomValue("varchar",32));
        applyToProgEmployAddDTO.setEmployId(getRandomValue("varchar",32));
        applyToProgEmployAddDTO.setCompanyId(getRandomValue("varchar",32));
        return applyToProgEmployAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ApplyToProgEmployUpdateDTO
     */
    public ApplyToProgEmployUpdateDTO getApplyToProgEmployUpdateDTO(ApplyToProgEmployVO applyToProgEmployVO){
        return applyToProgEmployService.selectDOById(applyToProgEmployVO.getId(), SITE_ID).to(ApplyToProgEmployUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ApplyToProgEmployQuery
     */
    public ApplyToProgEmployQuery getApplyToProgEmployQuery() {
        ApplyToProgEmployQuery applyToProgEmployQuery = new ApplyToProgEmployQuery();
        List<ApplyToProgEmployDO> applyToProgEmployDOList = applyToProgEmployService.list(new ApplyToProgEmployDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(applyToProgEmployDOList)) {
            ApplyToProgEmployDO applyToProgEmployDO = applyToProgEmployDOList.get(0);
            applyToProgEmployQuery = applyToProgEmployDO.to(ApplyToProgEmployQuery.class);
            if (applyToProgEmployDO.getGmtCreate() != null) {
                applyToProgEmployQuery.setGmtCreateStart(DateKit.getBeforeDay(applyToProgEmployDO.getGmtCreate(),-1));
                applyToProgEmployQuery.setGmtCreateEnd(DateKit.getBeforeDay(applyToProgEmployDO.getGmtCreate(),1));
            }
        }
        return applyToProgEmployQuery;
    }

    /**
     * 保存示例
     * @return ApplyToProgEmployVO
     */
    public ApplyToProgEmployVO saveApplyToProgEmployExample(){
        ApplyToProgEmployAddDTO addDTO = this.getApplyToProgEmployAddDTO();
        ApplyToProgEmployVO applyToProgEmployVO = applyToProgEmployService.save(addDTO,buildTokenUser());
        return applyToProgEmployVO;
    }


}

